package com.practice.details;

import java.util.Iterator;
import java.util.List;

public class MyIterator implements Iterator<Integer> {
	private List<List<Integer>>		data;
	private int						row;
	private int						col;
	
	public MyIterator(List<List<Integer>> data) {
		this.data = data;
		this.row = 0;
		this.col = -1;
		moveCursor();
	}
	
	public boolean hasNext() {
		return row < data.size();
	}

	public Integer next() throws ArrayIndexOutOfBoundsException {
		if (!hasNext()) throw new ArrayIndexOutOfBoundsException();
		Integer t = data.get(row).get(col);
		moveCursor();
		return t;
	}
	
	private void moveCursor() {
		if (row >= data.size()) return;
		col++;
		if (col >= data.get(row).size()) {
			col = -1;
			row++;
			moveCursor();
		}
	}

	public void remove() {
		//TODO ...
	}

}
